﻿using System;
using System.Windows.Forms;

namespace CodeCrawler.UI.Forms.ChildForms {
    public partial class DreadCalculator : Form {

        private Tools.Dread_Calculator.DreadCalculatorCore DreadObject;

        /// <summary>
        /// Constructor
        /// </summary>
        public DreadCalculator() {
            InitializeComponent();

            DreadObject = new Tools.Dread_Calculator.DreadCalculatorCore();
        }

        /// <summary>
        /// Damage Potential has Changed Value
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DamagePotentialChanged(object sender, EventArgs e) {
            switch (uiDamagePotential.Value) {
                case 1:
                    DreadObject.DamagePotential = 5;
                    uiDamagePotentialDescription.Text = @"Individual Data is compromised or affected";
                    break;

                case 2:
                    DreadObject.DamagePotential = 10;
                    uiDamagePotentialDescription.Text = @"Complete system or data distruction";
                    break;

                case 0:
                    DreadObject.DamagePotential = 0;
                    uiDamagePotentialDescription.Text = @"Nothing";
                    break;
            }

            uiDreadResult.Text = DreadObject.DoCalculation().ToString();
        }

        /// <summary>
        /// Reproducibility value has changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReproducibilityHasChanged(object sender, EventArgs e) {
            switch (uiReproducibility.Value) {
                case 1:
                    DreadObject.Reproducibility = 5;
                    uiReproducibilityDescription.Text = "One or two steps required, may need to be an authorized user.";
                    break;

                case 2:
                    DreadObject.Reproducibility = 10;
                    uiReproducibilityDescription.Text = "Just a web browser and the address bar is sufficient, without authentication.";
                    break;

                case 0:
                    DreadObject.Reproducibility = 0;
                    uiReproducibilityDescription.Text = "Very hard or impossible, even for administrators of the application";
                    break;
            }

            uiDreadResult.Text = DreadObject.DoCalculation().ToString();
        }


        /// <summary>
        /// Exploitability value has changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExploitabilityHasChanged(object sender, EventArgs e) {
            switch (uiExploitability.Value) {
                case 1:
                    DreadObject.Exploitability = 5;
                    uiExploitabilityDescription.Text = "Malware exists on the Internet, or an exploit is easily performed, using available attack tools.";
                    break;

                case 2:
                    DreadObject.Exploitability = 10;
                    uiExploitabilityDescription.Text = "Just a web browser";
                    break;

                case 0:
                    DreadObject.Exploitability = 0;
                    uiExploitabilityDescription.Text = "Advanced programming and networking knowledge, with custom or advanced attack tools.";
                    break;
            }

            uiDreadResult.Text = DreadObject.DoCalculation().ToString();
        }

        /// <summary>
        /// Affected User value has changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AffectedUserHasChanged(object sender, EventArgs e) {
            switch (uiAffectedUser.Value) {
                case 1:
                    DreadObject.AffectedUsers = 5;
                    uiAffectedUserDescription.Text = "Some users, but not all";
                    break;

                case 2:
                    DreadObject.AffectedUsers = 10;
                    uiAffectedUserDescription.Text = "All Users";
                    break;

                case 0:
                    DreadObject.AffectedUsers = 0;
                    uiAffectedUserDescription.Text = "None";
                    break;
            }

            uiDreadResult.Text = DreadObject.DoCalculation().ToString();
        }

        /// <summary>
        /// Discoverability value has changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DiscoverabilityHasChanged(object sender, EventArgs e) {
            switch (uiDiscoverability.Value) {
                case 1:
                    DreadObject.Discoverability = 5;
                    uiDiscoverabilityDescription.Text = "Can figure it out by guessing or by monitoring network traces.";
                    break;

                case 2:
                    DreadObject.Discoverability = 9;
                    uiDiscoverabilityDescription.Text = "Details of faults like this are already in the public domain and can be easily discovered using a search engine.";
                    break;

                case 3:
                    DreadObject.Discoverability = 10;
                    uiDiscoverabilityDescription.Text = "The information is visible in the web browser address bar or in a form.";
                    break;

                case 0:
                    DreadObject.Discoverability = 0;
                    uiDiscoverabilityDescription.Text = "Very hard to impossible; requires source code or administrative access.";
                    break;
            }

            uiDreadResult.Text = DreadObject.DoCalculation().ToString();
        }
    }
}